<template>
  <div id="app">
    <ul>
      <li v-for="(item, index) in arr" :key="index">
        <span>{{ item }}</span>
        <button @click="del(index)">删除</button>
      </li>
    </ul>
    <button @click="rodomNum">生成</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arr: [1, 5, 3]
    }
  },
  methods: {
    rodomNum() {
      //   生成一个随机数插入到数组
      let num = parseInt(Math.random() * 100)
      this.arr.push(num)
    },
    del(e) {
      this.arr.splice(e, 1)
    }
  }
}
</script>
